{{#if (or (eq runtime "bun") (eq runtime "node") (eq runtime "none"))}}
{{#if (and (ne backend "self") (includes frontend "next"))}}
import dotenv from "dotenv";

dotenv.config({
	path: "../../apps/server/.env",
});

{{/if}}
{{#if (eq dbSetup "neon")}}
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import ws from "ws";

neonConfig.webSocketConstructor = ws;

// To work in edge environments (Cloudflare Workers, Vercel Edge, etc.), enable querying over fetch
// neonConfig.poolQueryViaFetch = true

const sql = neon(process.env.DATABASE_URL || "");
export const db = drizzle(sql);
{{else}}
import { drizzle } from "drizzle-orm/node-postgres";

export const db = drizzle(process.env.DATABASE_URL || "");
{{/if}}
{{/if}}

{{#if (eq runtime "workers")}}
{{#if (eq dbSetup "neon")}}
import { neon, neonConfig } from '@neondatabase/serverless';
import { drizzle } from 'drizzle-orm/neon-http';
import { env } from "cloudflare:workers";
import ws from "ws";

neonConfig.webSocketConstructor = ws;
neonConfig.poolQueryViaFetch = true;

const sql = neon(env.DATABASE_URL || "");
export const db = drizzle(sql);
{{else}}
import { drizzle } from "drizzle-orm/node-postgres";
import { env } from "cloudflare:workers";

export const db = drizzle(env.DATABASE_URL || "");
{{/if}}
{{/if}}
